<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%
    String id = (String) request.getAttribute("id");
%>
<html>
<head>
    <script type="text/javascript">
        var advInfoUrl = "talent/talentInfo.do";
        $(document).ready(function () {
            var id =<%=id%>;
            $('#Adv-fm').form('syncLoad', advInfoUrl + "?id=" + id);
            $("#imageurlx").attr("src", basePath + $('#photoPath').val());
        });
        $("#submit_upload_identificationPhoto").click(function (){
            var filename = $("#advertisementPic").val();
            var extStart=filename.lastIndexOf(".");
            var ext=filename.substring(extStart,filename.length).toUpperCase();
            if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
                $messager.alert("操作提示", "图片限于bmp,png,gif,jpeg,jpg格式", "error");
                return;
            }
            $.ajaxFileUpload({
                url:'rest/uploadToFastDFS.do',
                secureuri: false,
                fileElementId: 'advertisementPic',
                data:null,
                dataType: 'text',
                success: function (data, status){
                    data = data.replace("<PRE>", '');  //ajaxFileUpload会对服务器响应回来的text内容加上<pre>text</pre>前后缀
                    data = data.replace("</PRE>", '');
                    data = data.replace("<pre>", '');
                    data = data.replace("</pre>", '');
                    var obj = eval("("+data+")");
                    if(obj.states=="0"){
                        $('#imageidx').val(obj.ImageId);
                        $('#photoPath').val(obj.imgUri);
                        $("#imageurlx").attr("src",basePath + obj.imgUri);
                        $("#imgx").show();
                    }else{
                        alert(obj.msg);
                    }
                },
                error: function (data, status, e){
                    alert("上传失败");
                }
            });
        });
        function updateTalent() {
            $('#Adv-fm').form('submit', {
                url: "talent/editTalent.do",
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.retCode == '0000') {
                        back("talent/index.do");
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    }
                }
            });
        }


        function back(url) {
            $.get(url, {}, function(data) {
                $("#center").empty();
                $("#center").html(data);
                $.parser.parse($("#center"));
            });
        }
    </script>
</head>
<body>
<div class="linkbar"><a>人才库管理</a>/<a>编辑人才库</a></div>
<div id="Adv-add">
    <form id="Adv-fm" method="post" novalidate>
        <input type="hidden" name="id"/>
        <div class="fitem">
            <label>职位：</label> <input name="position"
                                      style="width:200px;"
                                      class="easyui-validatebox" missingMessage="该输入项不能为空！"
                                      required="true"/>
        </div>
        <div class="fitem">
            <label>工作地点：</label> <input name="place"
                                        style="width:200px;"
                                        class="easyui-validatebox" missingMessage="该输入项不能为空！"
                                        required="true"/>
        </div>
        <div class="fitem">
            <label>图片:</label>
            <input type="file" id="advertisementPic" name="photo"
                   missingMessage="该输入项不能为空！" style="width:200px;"
                   required="true" />
            <a class="easyui-linkbutton" id="submit_upload_identificationPhoto">上传图片</a>
            <font color="red">*请先上传图片，再进行保存</font>
        </div>

        <div id="imgx"  class="shangc_nav clearfix">
            <img id="imageurlx" src="" style="width:100px;"/>
            <input type="hidden" name="photoPath" id="photoPath" class="easyui-validatebox" missingMessage="该输入项不能为空！"
                   required="true"/>
        </div>
        <div class="fitem">
            <label>备注：</label>
            <textarea name="remark" style="height: 80px; width: 300px;"
                      class="easyui-validatebox"
                      data-options="validType:['length[1,5000]']" />
        </div>
    </form>
    <div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="updateTalent()">保存</a> <a href="#" class="easyui-linkbutton"
                                          iconCls="icon-cancel" onclick="back('talent/index.do')">返回</a>
</div>
</div>
</body>
</html>